#import "ALTemplateSelectorHeaderView.h"



#pragma mark Constants
static const CGFloat ALTemplateSelectorHeaderCornerRadius = 6.0f;


#pragma mark -
#pragma mark Class Globals
static NSGradient *ALTemplateSelectorHeaderBackgroundGradient;
static NSColor *ALTemplateSelectorHeaderBorderColor;


#pragma mark -
@interface ALTemplateSelectorHeaderView (ALTemplateSelectorHeaderViewPrivateMethods)

@end


#pragma mark -
@implementation ALTemplateSelectorHeaderView


+(void)initialize {
	NSColor *startColor = [NSColor colorWithCalibratedWhite:0.641 alpha:1.000];
	NSColor *endColor = [NSColor colorWithCalibratedWhite:0.818 alpha:1.000];
	ALTemplateSelectorHeaderBackgroundGradient = [[NSGradient alloc] initWithStartingColor:startColor endingColor:endColor];
	ALTemplateSelectorHeaderBorderColor = [NSColor colorWithCalibratedWhite:0.318 alpha:1.0];
}

-(void)drawRect:(NSRect)dirtyRect {
	NSRect bounds = [self bounds];
	CGFloat minx = bounds.origin.x;
	CGFloat maxx = NSMaxX(bounds);
	CGFloat miny = bounds.origin.y;
	CGFloat maxy = NSMaxY(bounds);
	NSBezierPath *framePath = [NSBezierPath bezierPath];
	[framePath moveToPoint:bounds.origin];
	[framePath lineToPoint:NSMakePoint(minx, maxy - ALTemplateSelectorHeaderCornerRadius)];
	[framePath appendBezierPathWithArcFromPoint:NSMakePoint(minx, maxy) toPoint:NSMakePoint(minx + ALTemplateSelectorHeaderCornerRadius, maxy) radius:ALTemplateSelectorHeaderCornerRadius];
	[framePath lineToPoint:NSMakePoint(maxx - ALTemplateSelectorHeaderCornerRadius, maxy)];
	[framePath appendBezierPathWithArcFromPoint:NSMakePoint(maxx, maxy) toPoint:NSMakePoint(maxx, maxy - ALTemplateSelectorHeaderCornerRadius) radius:ALTemplateSelectorHeaderCornerRadius];
	[framePath lineToPoint:NSMakePoint(maxx, miny)];
	[framePath closePath];
	[[NSGraphicsContext currentContext] setShouldAntialias:NO];
	[ALTemplateSelectorHeaderBackgroundGradient drawInBezierPath:framePath angle:90];
	[ALTemplateSelectorHeaderBorderColor setStroke];
	[NSBezierPath strokeLineFromPoint:NSMakePoint(minx, miny) toPoint:NSMakePoint(maxx, miny)];
}

@end
